package abinly.harmony.permission.slice;

import abinly.harmony.permission.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

@CompilePermissions
public class MainAbilitySlice extends AbilitySlice {

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_text_helloworld).setClickedListener((Component component) -> {
            MainAbilitySlicePermissionHelper.selfCameraPermission(this);
        });

    }

    @NeedsSelfPermission("ohos.permission.CAMERA")
    public void selfCameraPermission() {
        new ToastDialog(getAbility()).setText("self permission success.").show();
    }

    @NeedsCallingPermission("ohos.permission.CAMERA")
    public void callingCameraPermission() {
        new ToastDialog(getAbility()).setText("calling permission success.").show();
    }

    @NeedsCallingOrSelfPermission("ohos.permission.CAMERA")
    public void callingOrSelfCameraPermission() {
        new ToastDialog(getAbility()).setText("calling or self permission success.").show();
    }

    @OnPermissionBlocked("ohos.permission.CAMERA")
    public void onNeverAskAgain() {
        new ToastDialog(getAbility()).setText("request permission fail.").show();
    }

    @NeedsSelfPermission({"ohos.permission.CAMERA", "ohos.permission.DISTRIBUTED_DATASYNC"})
    public void requestDistributredDataSync() {
        new ToastDialog(getAbility()).setText("self permission success.").show();
    }

}
